package com.summatech.gwt.mvp.client.presenter;

import com.google.inject.Inject;
import com.mvp4g.client.event.EventBus;
import com.mvp4g.client.presenter.BasePresenter;
import com.summatech.gwt.mvp.client.handler.PresenterHandler;

public abstract class AbstractGroupPresenter<V, E extends EventBus> extends
		BasePresenter<V, E> {

	private String group;

	public void setGroup(String group) {
		this.group = group;
	}

	public String getGroup() {
		return group;
	}

	protected boolean isThisGroup(String groupCheck) {
		if (groupCheck == null || groupCheck.equals("")) {
			return false;
		} else {
			return groupCheck.equals(group);
		}
	}

	/*
	 * Method override to check whether the event is for this event group. This
	 * is the piece that handles the event filtering mechanism by looking at
	 * PresenterHandler.activeEventGroup.
	 */
	@Override
	public boolean isActivated(boolean passive) {
		if (group != null && !group.equals("")) {
			return group.equals(presenterHandler.getActiveEventGroup())
					&& super.isActivated(passive);
		} else {
			return super.isActivated(passive);
		}
	}

	@Inject
	PresenterHandler presenterHandler;
}
